package com.ajk.shop.dao.provider;

import java.util.List;
import java.util.Map;

import com.ajk.shop.model.GoodsImage;
/**
 *   <br>
 * goods_image <br>
 * v1.0 2016-06-27
 * @see com.ajk.server.dao.GoodsImageMapper
 */
 public class GoodsImageProvider {
 
 	/**
 	* 新增 
 	*/
 	public String insert(GoodsImage domain){
		StringBuilder sb = new StringBuilder();
		
		sb.append("insert into goods_image(");
	 	if(domain.getGoodsId()!=null){
			sb.append("goods_id");
		}
	 	if(domain.getImageSmall()!=null){
			sb.append(",image_small");
		}
	 	if(domain.getImageLarge()!=null){
			sb.append(",image_large");
		}
	 	if(domain.getSortOrder()!=null){
			sb.append(",sort_order");
		}
	 	if(domain.getStatus()!=null){
			sb.append(",status");
		}
		
		sb.append(") values ( ");
		
	 	if(domain.getGoodsId()!=null){
			sb.append("#{goodsId}");
		}
	 	if(domain.getImageSmall()!=null){
			sb.append(",#{imageSmall}");
		}
	 	if(domain.getImageLarge()!=null){
			sb.append(",#{imageLarge}");
		}
	 	if(domain.getSortOrder()!=null){
			sb.append(",#{sortOrder}");
		}
	 	if(domain.getStatus()!=null){
			sb.append(",#{status}");
		}
		sb.append(")");
		
		return sb.toString();
	}

	/**
 	* 更新 
 	*/
	public String update(GoodsImage domain){
		StringBuilder sb = new StringBuilder();
		
		sb.append("update goods_image set id = id ");
		
		if(domain.getGoodsId()!=null){
			sb.append(",goods_id=#{goodsId}");
		}
		if(domain.getImageSmall()!=null){
			sb.append(",image_small=#{imageSmall}");
		}
		if(domain.getImageLarge()!=null){
			sb.append(",image_large=#{imageLarge}");
		}
		if(domain.getSortOrder()!=null){
			sb.append(",sort_order=#{sortOrder}");
		}
		if(domain.getStatus()!=null){
			sb.append(",status=#{status}");
		}
		
		sb.append(" where id=#{id}");
		
		return sb.toString();
	}
	
	/**
 	*通过ids 查询 
 	*/
 	public String findByIds(Map<String, List<Integer>> map){
		StringBuffer sb = new StringBuffer();
		List<Integer> ids = map.get("list");
		sb.append("select * from goods_image where ");
		if(ids==null || ids.isEmpty()){
			sb.append(" 1=2");
		}else{
			if(ids.size()==1){
				sb.append(" id=").append("#{list[0]}");
			}else{
				sb.append(" id in (").append("#{list[0]}");
				for(int i=1; i<ids.size() ; i++){
					sb.append(",").append("#{list[").append(i).append("]}");
				}
				sb.append(")");
			}
		}
		return sb.toString();
	}
	
 }	